/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.situ.studentmanagement.service;

import com.situ.studentmanagement.database.DBHelper;
import com.situ.studentmanagement.model.Admin;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author niugao
 */
public class AdminManService {
    
    //检查帐户和密码是否能登录，返回值是帐户的ID，如果不存在则为0
    public int login(String userName, String password) throws ClassNotFoundException, SQLException {
        //管理员登录
        //如果提交了注册信息，验证之
        String sql = "select id from " + Admin.TABLE_NAME
                + " where " + Admin.NAME + "='" + userName + "' and "
                + Admin.PASSWORD + "='" + password + "'";

        Connection conn = DBHelper.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        
        int loginID=0;
        if (rs.next()) {
            loginID = rs.getInt(1);
        }

        conn.close();
        stmt.close();
        
        return loginID;
    }
   
}
